package cn.zlb.frame.domain.pay.model.entity;

import cn.zlb.frame.common.vo.BaseVO;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author yangjie.deng@resico.cn
 * @date 2023-11-09 13:33:45
 * @describe class responsibility
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ProductEntity extends BaseVO {
    /**
     *  用户编号
     */
    private String userNo;

    /**
     *  产品编号
     */
    private String productNo;

    /**
     *  库存
     */
    private Integer inventory;

    /**
     *  库存剩余校验
     *
     * @param inventory 本次扣减库存
     */
    public void hasInventory(Integer inventory) {
        final int overage = Math.subtractExact(this.getInventory(), inventory);
        if (overage < 0) {
            throw new RuntimeException("库存不足,无法完成支付");
        }
    }
}
